const { db, saveMaven, getBreakPoint, saveBreakPoint, getRunning, addRunning, delRunning, clearRunning } = require('../db-helper');
const fs = require('fs')


function test1() {
  let mavenList = fs.readFileSync('/home/lianzt/Downloads/fsdownload/maven.txt', { encoding: 'utf-8' })
    .split('\n')
    .map(line => {
      let arr = line.split(', ')
      // console.log(arr)
      try {
        let groupId = arr[0].split('=')[1]
        let artifactId = arr[1].split('=')[1]
        let version = arr[2].split('=')[1]

        if (groupId && artifactId && version) {
          return { groupId, artifactId, version }
        }
      } catch (e) {
        console.log('error:' + e)
        console.log('===>' + line)
      }
      return {}
    })
    .filter(row => row.groupId)

  console.log(mavenList.length)

  for (let i = 0, step = 10000; i < mavenList.length; i += step) {
    console.log(i)
    saveMaven(mavenList.slice(i, i + step))
  }
}

function testUpdate() {
  let num = db.update('update breakpoint set url=? where pk=1', '123')
  console.log('-->' + num)
}

function testBreakpoint() {
  console.log('break point : ' + getBreakPoint())
  saveBreakPoint('1234678123123123')
  console.log('break point : ' + getBreakPoint())
}

function testRunning() {
  console.log('running : ', getRunning())
  addRunning('test')
  addRunning('test1')
  addRunning('test2')
  console.log('running : ', getRunning())

  delRunning('test')
  console.log('running : ', getRunning())

  delRunning('test1')
  delRunning('test2')
  console.log('running : ', getRunning())
}

function testClearRun() {
  addRunning('test')
  addRunning('test1')
  addRunning('test2')
  console.log('running : ', getRunning())

  clearRunning()
  
  console.log('running : ', getRunning())
}

testClearRun()